﻿using System;
using System.Threading.Tasks;

namespace Beeflys
{
    public static class ActorRefExtensions
    {
        public static MessengerOperator<TMessenger> Messenger<TMessenger>(this IActorRef target)
            where TMessenger : IActorMessengerDefine
        {
            return target.Messenger<TMessenger>(null, TimeSpan.Zero);
        }

        public static MessengerOperator<TMessenger> Messenger<TMessenger>(this IActorRef target, TimeSpan timeout)
            where TMessenger : IActorMessengerDefine
        {
            return target.Messenger<TMessenger>(null, timeout);
        }

        public static Task<ActorResult<T>> Call<T>(this IActorRef target, object o)
        {
            return target.CallAsync<T>(o, TimeSpan.Zero, null);
        }

        public static Task<ActorResult<T>> Call<T>(this IActorRef target, IActorRef source, object o)
        {
            return target.CallAsync<T>(o, TimeSpan.Zero, source);
        }





        internal static IEntityRef Entity(this IActorRef actorRef)
        {
            return (IEntityRef)actorRef;
        }
        internal static IFabledRef Fabled(this IActorRef actorRef)
        {
            return (IFabledRef) actorRef;
        }
    }
}